#!/usr/bin/python
# coding=utf-8

from pymemcache.client.base import Client
from datetime import datetime, timedelta, date
import random
import time
client = Client(('47.92.27.124', 11211))
def random_set_value():
    current_time = datetime.now()
    current_time = current_time.strftime("%Y-%m-%d %H:%M:%S")
    for i in range(1,10):
        # print(i)
        # print(type({"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time}))
        client.set('cms:1:gas_station_'+str(i)+'_temprature',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_oil_gas_concentration',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_one_pump_flow_value',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_two_pump_flow_value',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_three_pump_flow_value',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_four_pump_flow_value',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_gun_status',{"id":1,"value":'1,2',"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_gas_liquid_ratio',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_temperature',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_humidit',{"id":1,"value":round(random.uniform(0,30),2),"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_voltage',{"id":1,"input_voltage":round(random.uniform(10,20),2),"under_voltage_status":random.randint(0,1),'over_voltage_status':random.randint(0,1),"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_communication_status',{"id":1,"value":random.randint(0,1),"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_status',{"id":1,"value":random.randint(0,1),"create_time":current_time})
        client.set('cms:1:greaser_'+str(i)+'_is_alarm',{"id":1,"value":random.randint(0,1),"create_time":current_time})
        client.set('cms:1:gas_station_'+str(i)+'_power_distribution',{"id":1,"a_voltage":random.randint(10, 20),"a_line_voltage":random.randint(10, 20),"a_current":random.randint(10, 20),"a_power":random.randint(10, 20),"b_voltage":random.randint(10, 20),"b_line_voltage":random.randint(10, 20),
        "b_current":random.randint(10, 20),"b_power":random.randint(10, 20),"c_voltage":random.randint(10, 20),"c_line_voltage":random.randint(10, 20),"c_current":random.randint(10, 20),"c_power":random.randint(10, 20),"input_frequency":random.randint(10, 20),"input_userful_power":random.randint(10, 20),
        "status":random.randint(10, 20),"communication_status":random.randint(10, 20),"create_time":datetime.now().strftime('%Y-%m-%d %H:%M:%S')})

        client.set('cms:1:oilcan_gas_station_'+str(i)+'_pressure',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:oilcan_'+str(i)+'_oil_gas_concentration',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:water_seal_well_'+str(i)+'_oil_gas_concentration',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:operating_well_'+str(i)+'_oil_gas_concentration',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})

        client.set('cms:1:liquid_level_meter_'+str(i)+'_volume_realtime',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:liquid_level_meter_'+str(i)+'_volume_count',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:liquid_level_meter_'+str(i)+'_volume_water',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:liquid_level_meter_'+str(i)+'_volume_empty',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:liquid_level_meter_'+str(i)+'_volume_tc',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:liquid_level_meter_'+str(i)+'_height_oil',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:liquid_level_meter_'+str(i)+'_height_water',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:liquid_level_meter_'+str(i)+'_transfer_status',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:liquid_level_meter_'+str(i)+'_tightness',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})
        client.set('cms:1:liquid_level_meter_'+str(i)+'_ineffective_level_of_liquid_level_status',{"id":1,"value":round(random.uniform(10,20),2),"create_time":current_time})


    result = client.get('cms:1:gas_station_1_power_distribution')
    # print(result)

if __name__ == '__main__':
    while True:
        time.sleep(1)
        random_set_value()
